package kk;

import com.alibaba.fastjson.JSON;
import dao.basedb;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name="userServlet",urlPatterns = "/user")
public class userservlet extends HttpServlet {

    basedb db=new basedb();

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        response.setHeader("content-type", "text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        String sql="select * from userage";
        db.getConnection();
        List list =db.selectUser(sql);
        String user=JSON.toJSON(list).toString();
        response.getWriter().append(user);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
       doGet(request,response);
    }
}
